/**
 * Created by python on 18-11-10.
 */
var vm = new Vue({
    el: "#app",
    data:{  // 页面中需要使用到的数据，键值对
        activity:{},
        last_time:0,
        now:0,
        deadline:0,
        },
    computed:{// 需要通过计算得到的数据，键值对 ，键是名称，值是匿名函数

        },
    mounted:function () {// 一加载就需要做的，直接是代码
        id = get_id('id', null)
        axios.get(base+'activities/' + id, {
                responseType:'json'
            })
            .then(response => {
                console.info(response.data)
                this.activity = response.data;
                var now = new Date(Date());
                var deadline = response.data.apply_deadline
                console.log(now)
                this.tran(new Date(deadline).getTime(),now.getTime())
            })
            .catch(error => {
                alert("孩子，出错了")
            })
    },
    methods:{
        // 需要用到的函数，键值对 ，键是名称，值是匿名函数
        tran : function (deadline, now) {
            this.deadline = deadline
            this.now = now

            setInterval( () => {
                this.now += 1000;
                this.last_time = this.deadline - this.now
            },1000)
        }
    },
    filters: {
        daojishi : function (time) {
            var day = Math.floor(time/1000/3600/24);
            var hour = Math.floor(time/1000/3600 % 24);
            var minute = Math.floor(time/1000/60%60);
            var second = Math.floor(time/1000%60);
            if (time>0) {return day+'天'+hour+'时'+minute+'分'+second+'秒'}
            else {return "已结束"}
           
        }
    }
});
